<template>
	<view :class="[primarySize()]">
		<view class="container bg-white">
			<view class="page-head flex-box">
				<view class="tab_item flex-grow-1" :class="nindex==0?'active':''" @click="chooseNav(0)"
					v-if="user.group_id==1">全职</view>
				<view class="tab_item flex-grow-1" :class="nindex==5?'active':''" @click="chooseNav(5)"
					v-if="user.group_id==2">人才</view>
				<!-- <view class="tab_item flex-grow-1" :class="nindex==1?'active':''" @click="chooseNav(1)">零工</view> -->
				<view class="tab_item flex-grow-1" :class="nindex==1?'active':''" @click="chooseNav(1)">企业</view>
			</view>
			<view class="pt88 pb30">
				<template v-if="nindex==5">
					<template v-for="(pitem,index) in resumeDateList">
						<view class="date_info">{{pitem}}</view>
						<view class="plr30 ptb15">
							<template v-for="(item,qindex) in resumeDateMapList[pitem]">
								<navigator :url="'/pages/company/talent_details?id='+item.id" class="recom_item">
									<view class="recom_info">
										<view class="flex-box">
											<view class="flex-grow-1">
												<view class="recom_text flex-box">
													<view class="recom_tit flex-grow-1">{{item.personal.realname}}
													</view>
													<view class="col9 fs24">
														{{formatDatetime(item.updatetime,'yyyy-mm-dd')}}
													</view>
												</view>
												<template v-if="item.star">
													<view class="fs24 col3 pt20">期望岗位：<text
															class="col0">{{item.job_intention.fav_category.category_name}}</text>
													</view>
													<view class="fs24 col3 pt10">期望薪资：<text
															class="recom_price">{{item.job_intention.expect_salary.name}}/月</text>
													</view>
												</template>
												<view v-else class="recom_price">
													<text v-for="(intention,it_index) in item.job_intention"
														v-if="item.job_intention">{{intention.expect_salary.name}}/月{{it_index != item.job_intention.length - 1 ?'、':''}}</text>
												</view>
											</view>
										</view>

										<view class="recom_type clearfix">
											<view class="recom_type_item" v-if="item.job_intention"
												v-for="(item,it_index) in item.job_intention">
												{{intention.fav_city.shortname}}
											</view>
											<view class="recom_type_item" v-if="item.personal.work_experience.name">
												{{item.personal.work_experience.name}}
											</view>
											<view class="recom_type_item" v-if="item.personal.education_level.name">
												{{item.personal.education_level.name}}
											</view>
											<view class="recom_type_item" v-if="item.job_intention.job_type_text">
												{{item.job_intention.job_type_text}}
											</view>
											<view class="recom_type_item" v-for="(tag,index) in item.personal_tags"
												v-if="item.personal_tags.length>0">
												{{tag.name}}
											</view>
										</view>
									</view>
									<view class="recom_business" v-if="!item.star">
										<image src="https://admin.mosizp.cn/static/public/icon_pack.png" mode="aspectFit"></image>
										<view class="col0">求职意向：
											<text v-if="item.job_intention.length>0"
												v-for="(intention,it_index) in item.job_intention">{{intention.fav_category.category_name}}</text>
										</view>
									</view>
									<view class="recom_btn flex-box" v-if="toggleFav">
										<button @click.stop="unfav(index)" hover-class="none"
											class="flex-grow-1">取消收藏</button>
										<button @click.stop="createInterview(index)" v-if="showInterview"
											hover-class="none" class="flex-grow-1 invite">面试邀请</button>
									</view>
									<image v-if="item.top" src="https://admin.mosizp.cn/static/public/icon54.png" class="icon_recommend">
									</image>
								</navigator>
							</template>
						</view>
					</template>
					<view class="mlr30">
						<view class="nothing" v-if="resumeListMore.nothing">
							<image class="img_nothing" src="https://admin.mosizp.cn/static/public/icon_nothing.png" mode="aspectFill">
							</image>
							<view>抱歉，暂无相关信息</view>
						</view>
						<button ontap="fetchResume" v-else hover-class="none"
							class="more_btn mt30 mb30">{{resumeListMore.text}}</button>
					</view>
				</template>
				<template v-if="nindex==0">
					<template v-for="(item,index) in jobDateList">
						<view class="date_info mt30">{{item}}</view>
						<view class="plr30">
							<job-list :jobs="jobDateMapList[item]"></job-list>
						</view>
					</template>
					<view class="nothing" v-if="jobsMore.nothing">
						<image src="https://admin.mosizp.cn/static/public/icon_nothing.png" mode="aspectFit"></image>
						<text>暂无职位</text>
					</view>
					<view class="plr30 pt30" v-else>
						<view class="more_btn" @click="fetchJob()">{{jobsMore.text}}</view>
					</view>
				</template>
				<!-- <template v-if="nindex==1">
					
					<task-list :tasks="taskLists"></task-list>
					<view class="nothing" v-if="taskMore.nothing">
						<image src="https://admin.mosizp.cn/static/public/icon_nothing.png" mode="aspectFit"></image>
						<text>暂无零工</text>
					</view>
					<view class="g-btn3-wrap" v-else>
						<view class="g-btn3" @click="fetchTask()">{{jobsMore.text}}</view>
					</view>
					
				</template> -->
				<template v-if="nindex==1">
					<template v-for="(item,index) in companyDateList">
						<view class="date_info mt30">{{item}}</view>
						<view class="plr30">
							<company-list :companies="companyDateMapList[item]"></company-list>
						</view>
					</template>
					<view class="nothing" v-if="companyListMore.nothing">
						<image src="https://admin.mosizp.cn/static/public/icon_nothing.png" mode="aspectFit"></image>
						<text>暂无公司信息</text>
					</view>
					<view class="plr30 pt30" v-else>
						<view class="more_btn" @click="fetchCompany()">{{companyListMore.text}}</view>
					</view>
				</template>
			</view>



		</view>
	</view>
</template>

<script>
	const app = getApp();
	import jobList from '../../components/job-list/job-list.vue';
	import taskList from '../../components/task-list/task-list.vue';
	import companyList from '../../components/company-list/company-list.vue';
	export default {
		components: {
			jobList,
			taskList,
			companyList
		},
		data() {
			return {
				user: {},
				nindex: 0,
				jobs: [],
				jobsMore: {
					page: 1
				},
				jobDateList: [],
				jobDateMapList: {}, //key 'yyyy-mm-dd', value job list
				resumeList: [],
				resumeDateList: [],
				resumeDateMapList: {},
				resumeListMore: {
					page: 1
				},
				companyList: [],
				companyListMore: {
					page: 1
				},
				companyDateList: [],
				companyDateMapList: {},
				taskLists: [],
				taskMore: {
					page: 1
				},
			}
		},
		onReady() {
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.primaryColor()
			})
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			this.user = this.$core.getUserinfo();
			this.fetchJob();
			if (this.user.group_id == 1) {
				this.fetchJob();
				this.nindex = 0;
			} else {
				this.nindex = 5;
				this.fetchResume();
			}
			// this.fetchTask();
			this.fetchCompany();
		},
		onReachBottom() {
			if (this.nindex == 1) {
				this.fetchCompany();
			} else {
				this.fetchJob();
			}
		},
		methods: {
			chooseNav(index) {
				this.nindex = index
			},
			fetchResume() {
				this.$util.fetch(this, 'xilujob.resume/my_look', {}, 'resumeListMore', 'resumeList', 'data', list => {
					list.data.forEach(resume => {
						let viewDate = this.$util.formatDatetime(resume.view_time, 'yyyy年m月d日');
						if (this.resumeDateList.indexOf(viewDate) === -1) {
							this.resumeDateList.push(viewDate);
						}
						let resumeList = this.resumeDateMapList[viewDate] || [];
						resumeList.push(resume);
						this.$set(this.resumeDateMapList, viewDate, resumeList)
					});
					return [];
				});
			},
			fetchJob() {
				this.$util.fetch(this, 'xilujob.job/my_look', {}, 'jobsMore', 'jobs', 'data', list => {
					list.data.forEach(job => {
						let viewDate = this.$util.formatDatetime(job.view_time, 'yyyy年m月d日');
						if (this.jobDateList.indexOf(viewDate) === -1) {
							this.jobDateList.push(viewDate);
						}
						let jobList = this.jobDateMapList[viewDate] || [];
						jobList.push(job);
						this.$set(this.jobDateMapList, viewDate, jobList);
					});
					return [];
				});
			},
			fetchTask() {
				let query = {};
				query.pagesize = 10;
				this.$util.fetch(this, 'xilujob.task/my_look', query, 'taskMore', 'taskLists', 'data', data => {

				})
			},
			fetchCompany() {
				this.$util.fetch(this, 'xilujob.company/my_look', {
					pagesize: 10
				}, 'companyListMore', 'companyList', 'data', list => {
					list.data.forEach(company => {
						let viewDate = this.$util.formatDatetime(company.view_time, 'yyyy年m月d日');
						if (this.companyDateList.indexOf(viewDate) === -1) {
							this.companyDateList.push(viewDate);
						}
						let companyList = this.companyDateMapList[viewDate] || [];
						companyList.push(company);
						this.$set(this.companyDateMapList, viewDate, companyList);
					});
					return [];
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.pt88 {
		padding-top: 88rpx;
	}

	.page-head {
		height: 88rpx;
		background: var(--primary);

		.tab_item {
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			font-size: 26rpx;
			color: #FFFFFF;

			&.active {
				font-weight: bold;
				font-size: 26rpx;
				color: #FFFFFF;
				position: relative;

				&::after {
					content: '';
					width: 36rpx;
					height: 6rpx;
					background: #FFFFFF;
					border-radius: 4rpx;
					position: absolute;
					bottom: 0;
					left: 50%;
					transform: translateX(-50%);
				}
			}
		}
	}

	.post {
		&_list {
			padding-top: 10rpx;
		}

		&_item {
			width: 690rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(0, 0, 0, 0.03);
			border-radius: 18rpx;
			margin-top: 20rpx;
			padding: 30rpx;

			.maxw60 {
				max-width: 60%;
			}

			.urgent {
				width: 74rpx;
				height: 37rpx;
				line-height: 33rpx;
				text-align: center;
				font-size: 24rpx;
				color: var(--primary);
				border-radius: 6rpx;
				border: 2rpx solid var(--primary);
			}

			.tips_item {
				height: 32rpx;
				background: #ECEFF5;
				border-radius: 4rpx;
				font-weight: 400;
				font-size: 22rpx;
				color: #A5A5A5;
				line-height: 32rpx;
				display: inline-block;
				vertical-align: top;
				margin-right: 10rpx;
				margin-top: 10rpx;
				padding: 0 8rpx;
			}

			.cover {
				width: 40rpx;
				height: 40rpx;
				border-radius: 50%;
			}
		}
	}

	.comp_item {
		width: 690rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(0, 0, 0, 0.03);
		border-radius: 18rpx;
		margin-top: 20rpx;
		padding: 10rpx 30rpx;

		.cover {
			width: 183rpx;
			height: 195rpx;
		}

		.label {
			padding: 0 8rpx;
			font-size: 22rpx;
			color: #A5A5A5;
			line-height: 32rpx;
			height: 32rpx;
			display: inline-block;
			vertical-align: top;
			margin-top: 20rpx;
			margin-right: 20rpx;
			background: #ECEFF5;
			border-radius: 4rpx;
		}
	}

	.date_info {
		line-height: 60rpx;
		background-color: #F4F4F4;
		font-size: 24rpx;
		color: #999999;
		padding: 0 30rpx;
	}

	.recom_item {
		box-shadow: 0px 1px 18px 0px rgba(0, 0, 0, 0.06);
		background-color: #fff;
		border-radius: 4rpx;
		border: 1rpx solid #EBEBEB;
		margin-bottom: 18rpx;
		padding-top: 35rpx;
		position: relative;
		overflow: hidden
	}

	.recom_text .top {
		position: absolute;
		top: 0;
		right: 0;
		width: 74rpx;
		height: 74rpx;
	}

	.recom_item:nth-last-child(1) {
		margin-bottom: 0;
	}

	.recom_tit {
		font-size: 32rpx;
		color: #333;
		font-weight: bold;
		display: inline-block;
		vertical-align: middle
	}

	.recom_price {
		font-size: 28rpx;
		color: var(--primary);
		font-weight: bold;
		padding-top: 20rpx;
	}

	.recom_type {
		padding-top: 20rpx;
	}

	.recom_type_item {
		font-size: 20rpx;
		color: #999;
		background-color: #F7F7F7;
		float: left;
		line-height: 39rpx;
		padding: 0 15rpx;
		border-radius: 8rpx;
		margin-right: 17rpx;
		margin-bottom: 17rpx;
	}

	.recom_info {
		padding: 0 30rpx 15rpx;
	}

	.clearfix {
		display: block;
	}

	.clearfix:after {
		content: "$";
		display: block;
		height: 0;
		clear: both;
		visibility: hidden;
		overflow: hidden;
	}

	.single-line {
		text-overflow: ellipsis;
		white-space: nowrap;
		overflow: hidden;
	}

	.multi-line {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}

	.recom_business {
		font-size: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 30rpx;
		border-top: 1rpx solid #F6F6F6
	}

	.recom_business image {
		width: 24rpx;
		height: 24rpx;
		margin-right: 7rpx;
		display: block;
	}

	.recom_business .col0 {
		color: #000;
		flex: 1;
		overflow: hidden
	}

	.recom_business .col9 {
		color: #999
	}

	.recom_text image {
		width: 32rpx;
		height: 32rpx;
		display: inline-block;
		vertical-align: middle;
		margin-left: 12rpx;
	}
</style>